﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using Microsoft.Practices.ServiceLocation;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Input;
using VolunteerManager.Model;

namespace VolunteerManager.ViewModel
{

    public class ProgramEditViewModel : ViewModelBase
    {
        private readonly IDataService _dataService;
        private ICommand saveCommand;
        private ICommand cancelCommand;
        private ICommand changePhotoCommand;
        private ProgramLog _vol;

        private ProgramLog _volClone;


        public ProgramLog CurrentVoluteer
        {
            get
            {
                return this._vol;
            }
            set
            {
                this._vol = value;
                //this._volClone = value.Clone();

                if (value.ID > 0)
                {
                    List<Group> GroupDataSource = ServiceLocator.Current.GetInstance<CommonDataSource>().GroupDataSource;

                    var resultList = from item in GroupDataSource
                                     where item.ID == _vol.GroupID
                                     select item;

                    var escortList = resultList.ToList();


                }
                this.RaisePropertyChanged("CurrentVoluteer");
            }
        }

        public void save()
        {

            
        }
        private void cancel()
        {
            //this._vol.RollBack(this._volClone);
           // Messenger.Default.Send<object>(null, "CloseEditWindow");
        }
        public ICommand SaveCommand
        {
            get
            {
                if (null == saveCommand)
                {
                    saveCommand = new RelayCommand(() => save());
                }
                return saveCommand;
            }
        }

        public ICommand CancelCommand
        {
            get
            {
                if (null == cancelCommand)
                {
                    cancelCommand = new RelayCommand(() => cancel());
                }
                return cancelCommand;
            }
        }
        
        public ICommand ChangePhotoCommand
        {
            get
            {
                if (null == changePhotoCommand)
                {
                    changePhotoCommand = new RelayCommand(() => changePhoeo());
                }
                return changePhotoCommand;
            }
        }

        private void changePhoeo()
        {
            
        }

        public ProgramEditViewModel(IDataService dataService)
        {
            _dataService = dataService;

            ProgramLog p = new ProgramLog() { Date = DateTime.Now, Leader="名称", DeputyLeader="ln" };
            if (IsInDesignMode)
            {
                this.CurrentVoluteer = p;
            }
            else {
                this.CurrentVoluteer = p;
            }
        }
    }
}
